﻿using System.Data;
using System.Collections.Generic;
using EaseDapper.Interface;
using System;

namespace EaseDapper
{
    /// <summary>
    ///  操作说明
    /// <![CDATA[
    /// public static List<Person> GetPersonList()
    /// {
    ///         var people = new List<Person>();
    ///         ExecuteWithoutTransaction(conn =>
    ///         {
    ///             people = conn.Query<Person>("select * from Person where id>@id", new { id = 2 }).ToList();
    ///         });
    ///         return people;
    /// }
    ///     ExecuteWithTransaction((conn, trans) =>
    /// {
    ///         var r = conn.Execute(@"update Person set password='www.lanhuseo.com' where id=@id", new { id = 1009 }, trans,
    ///                null, null);
    ///         r += conn.Execute("delete from Person where id=@id", new { id = 1010 }, trans, null, null);
    ///         return r;
    /// });
    /// ]]>
    ///  IDataOperation op1=new DataManager();
    ///  IEnumerable<test1> listinfo =op1.GetList<test1>("where id=@id", new { id = 1 });
    ///  DataTable dt = op1.Query("select * from test1 where id=@id", new { id = 1 });
    ///  IEnumerable<test1> listinfonew = op1.GetList<test1>();
    ///  test1 t1 = op1.Get<test1>(2);
    ///  test1 t1 = new test1();
    ///  t1.Id = 0;
    ///  t1.name = "测试";
    ///  int id = op1.AddBodyData(t1);
    ///  int id = op1.Delete<test1>(1)
    ///  test1 t1 = op1.GetModel<test1>(2);
    ///  t1.name = "测试";
    ///  int id = op1.Update(t1)
    /// </summary>
    public interface IDataManager
    {
        /// <summary>
        /// 添加,自增列返回当前值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Add<T>(T model) where T : class;

        /// <summary>
        /// 批量添加，自增列返回当前值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="models"></param>
        /// <returns></returns>
        int Add<T>(List<T> models) where T : class;
        /// <summary>
        /// 修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IUpdateExpressions<T> Update<T>() where T : class;
        /// <summary>
        /// 修改，返回影响行数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Update<T>(T model) where T : class;

        /// <summary>
        /// 批量修改，返回影响行数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Update<T>(List<T> model) where T : class;
        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IDeleteExpressions<T> Delete<T>() where T : class;
        /// <summary>
        /// 删除，返回影响行数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Delete<T>(T model) where T : class;

        /// <summary>
        /// 根据Id删除，返回影响行数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Id"></param>
        /// <returns></returns>
        int Delete<T>(object Id) where T : class;

        /// <summary>
        /// 根据Id获取对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        T Get<T>(object id) where T : class;

        /// <summary>
        /// 根据条件获取对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="whereConditions">条件信息，如where Age > @Age</param>
        /// <param name="Parameters">参数值，如new { Age = 10 }</param>
        /// <returns></returns>
        T Get<T>(string whereConditions, object Parameters = null) where T : class;

        /// <summary>
        /// 获取对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IEnumerable<T> GetList<T>() where T : class;

        /// <summary>
        /// 根据条件获取对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="whereConditions">条件信息，如where Age > @Age</param>
        /// <param name="Parameters">参数值，如new { Age = 10 }</param>
        /// <returns></returns>
        IEnumerable<T> GetList<T>(string whereConditions, object Parameters = null) where T : class;

        /// <summary>
        /// 查询,返回对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql">sql信息，如select * from test1 where id=@id</param>
        /// <param name="Parameters">参数，如new { id = 10 }</param>
        /// <returns></returns>
        IEnumerable<T> Query<T>(string sql, object Parameters = null) where T : class;

        /// <summary>
        /// 查询,返回对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IQueryExpressions<T> Query<T>() where T : class;
        /// <summary>
        /// 查询,返回datatable
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql">sql信息，如select * from test1 where id=@id</param>
        /// <param name="Parameters">参数，如new { id = 10 }</param>
        /// <returns></returns>
        DataTable Query(string sql, object Parameters = null);

        /// <summary>
        /// 执行sql操作
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="Parameters">参数</param>
        /// <returns></returns>
        int Execute(string sql, object Parameters = null);
    }
}
